/*
 * 创建日期 2006-9-21
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.vanda.report.dp;

import java.util.ArrayList;
import java.util.List;

import com.vanda.report.ReportException;
import com.vanda.report.ReportInnerData;
import com.vanda.report.Validation;
import com.vanda.report.element.BeanElement;

/**
 * @author amway
 *
 * 更改所生成类型注释的模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class UniteElement extends BeanElement{
	//待处理的数据,如果有多个,按","分隔
	private String data_src;
	
	//保存组织后的数据
	private String result_property = "reportList";
	
	/**
	 * 校验标签
	 */
	public void validator() throws ReportException {
		Validation.checkRequired("UniteElement","data_src",data_src);
	}
	
	/**
	 * 标签执行方法，递归执行
	 * @param obj
	 */
	public void execute(Object obj) throws ReportException {
		ReportInnerData reportData = (ReportInnerData) obj;

		try {
			//取得上下文数据
			Object contextObj = super.getNameObject(reportData);
			
			String[] dataSrcs = data_src.split(",");
			List resultList = new ArrayList();
			
			for(int i=0;i<dataSrcs.length;i++){
				Object dataSrc = super.getProperty(contextObj,dataSrcs[i]);
				if(dataSrc instanceof List){
					resultList.addAll((List)dataSrc);
				}else{
					resultList.add(dataSrc);
				}
			}
			//将处理后的list放入result_property
			super.setProperty(reportData,result_property,resultList);
			
			//递规执行方法
			super.execute(obj);
		} catch (ReportException e) {
			throw e;
		} catch (Exception e) {
			throw new ReportException(e);
		}
	}
	/**
	 * @return
	 */
	public String getData_src() {
		return data_src;
	}

	/**
	 * @return
	 */
	public String getResult_property() {
		return result_property;
	}

	/**
	 * @param string
	 */
	public void setData_src(String string) {
		data_src = string;
	}

	/**
	 * @param string
	 */
	public void setResult_property(String string) {
		result_property = string;
	}

}
